home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 1.2 KB | 58 lines | [TEXT/CWIE] |
- // Heap.h
-
- #ifndef Heap_h
- #define Heap_h
-
- #ifndef Integers_h
- #include "Integers.h"
- #endif
- #ifndef Assert_h
- #include "Assert.h"
- #endif
-
- template < class Element > class HeapLink;
-
- template < class Element >
- class Heap
- {
- typedef Element ElementType;
- typedef HeapLink< Element > LinkType;
- typedef Heap< Element > HeapType;
- typedef bool (ElementType::*Comparator)( const Element& ) const;
-
- private:
- uint32 nodeCount;
- LinkType *top;
- const Comparator below;
-
- LinkType** SubHeap( uint32 path );
- LinkType& RemoveLast();
-
- void SinkNode( LinkType**& subHeap, LinkType*& newNode );
- void Percolate( LinkType** subHeap );
-
- void Validate( LinkType& node, uint32 level ) const;
-
- // not implemented:
- Heap( const Heap& );
- void operator=( const Heap& );
-
- public:
- Heap( Comparator below ); // Typically operator<=( const Element& ) const
- ~Heap();
-
- Comparator Below() const { return below; }
-
- bool IsEmpty() const { return top == 0; }
-
- LinkType& Top() const { Assert( top != 0 ); return *top; }
- LinkType& Pop();
-
- void Add( LinkType& );
- void Remove( LinkType& );
-
- void Validate() const; // Checks a set of assertions
- };
-
- #endif
-